﻿using AutoMapper;
using ManagementApi.Models.Manage.ProjectSpecialAccount;
using Modules.Project;
using PmSoft;

namespace ManagementApi.Models.System.ProjectSpecialAccount
{
    public class ProjectSpecialAccountProjectDto : ProjectSpecialAccountDto
    {
        /// <summary>
        /// id
        /// </summary>
        public int Id { get; set; }

        /// <summary>
        /// 项目名称
        /// </summary>
        public string PrjName { get; set; }

        /// <summary>
        /// 项目编号
        /// </summary>
        public string PrjNum { get; set; }
    }

    public static partial class ProjectSpecialAccountProjectExceptions
    {
        /// <summary>
        /// 补全信息
        /// </summary>
        /// <param name="projectSpecialAccount"></param>
        /// <returns></returns>
        public static ProjectSpecialAccountProjectDto AsProjectSpecialAccountProjectDto(this Modules.BankSpecialAccount.Entitys.BankSpecialAccountInfo projectSpecialAccount)
        {
            ProjectSpecialAccountProjectDto dto = new ProjectSpecialAccountProjectDto();
            var projectService = ServiceAccessor.GetService<ProjectService>();
            var mapper = ServiceAccessor.GetService<IMapper>();
            mapper.Map(projectSpecialAccount, dto);
            dto.AccountStatusName = projectSpecialAccount.AccountStatus.GetDescription();
            ProjectInfo projectInfo = projectService.GetProjectInfo(projectSpecialAccount.ProjectId) ?? new ProjectInfo();
            dto.PrjName = projectInfo.Name;
            dto.PrjNum = projectInfo.PrjNum;
            return dto;
        }
    }
}